#ifndef PROJECTZ_NUSER_NCOMMAND_CMD_CS_REQ_QUEST_UPDATE_QUEST_H_
#define PROJECTZ_NUSER_NCOMMAND_CMD_CS_REQ_QUEST_UPDATE_QUEST_H_

#include "../../engine.h"

#include "../../User.h"

#include "../../NLogic/QuestInfo.h"

namespace ProjectZ { namespace NCommand { namespace NWorld {

class CS_REQ_QUEST_UPDATE_QUEST
{
public:
	static void OnExecute(User * pUser, ::Network::Packet * pPacket)
	{
		NLogic::QuestInfo * pQuestInfo = pUser->GetQuestInfo();
		if (NULL == pQuestInfo)
		{
			return;
		}

		PREPARE_PACKET;

		/*
		 * CS_REQ_QUEST_UPDATE_QUEST	0x2004		/// 퀘스트 데이터 변경
			{
				u8		    u8_idx;				/// index
				u16         u16_tid;			/// QUEST_ID
				u8          u8_achieve;        	/// 달성카운트
			}

			SC_REQ_QUEST_UPDATE_QUEST	0x2005		/// 퀘스트 데이터 변경
			{
				s16		s16_ack;	// 상태 변경 ack -1, 1
			}
		 */

		STRESSLOG("[CHANNEL] CS_REQ_QUEST_UPDATE_QUEST::ONEXECUTE");

		uint8_t 	u8_idx = 0;
		uint16_t 	u16_tid = 0;
		uint8_t	u8_achieve = 0;

		* pPacket >> u8_idx >> u16_tid >> u8_achieve;

		::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
		NLogic::QuestInfo::Quest * pQuest = pQuestInfo->GetQuest(u16_tid);
		if (NULL == pQuest)
		{
			* pAck << static_cast<int16_t>(ACK_NOT_EXIST_QUEST);
			pAck->MakePacket(CMD_SC_REQ_QUEST_UPDATE_QUEST);
			pUser->Send(pAck);
			return;
		}

		uint8_t old_achieve = pQuest->GetData()._achieve;
		pQuest->GetData()._achieve = u8_achieve;

		if (false == pQuest->UpdateQuestData())
		{
			pQuest->GetData()._achieve = old_achieve;

			* pAck << static_cast<int16_t>(ACK_DB_ERROR);
			pAck->MakePacket(CMD_SC_REQ_QUEST_UPDATE_QUEST);
			pUser->Send(pAck);
			return;
		}

		* pAck << static_cast<int16_t>(ACK_OK);
		pAck->MakePacket(CMD_SC_REQ_QUEST_UPDATE_QUEST);
		pUser->Send(pAck);
	}
};

} /*NWorld*/ } /*NCommand*/ } /*ProjectZ*/


#endif /* PROJECTZ_NUSER_NCOMMAND_CMD_CS_REQ_QUEST_UPDATE_QUEST_H_ */
